package com.neutech.maplestory.entity;

import com.neutech.maplestory.client.MapleStoryClient;
import com.neutech.maplestory.constant.Constant;
import com.neutech.maplestory.util.ImageUtil;

import java.awt.*;

public class BossArrow extends AbstractMapleStoryObject {
    public static Image[] images = new Image[20];
    static {
        /**
         * 怪物左面攻击的技能
         */
        for (int i = 0; i <8 ; i++) {
            images[i] = ImageUtil.getImage("boss_left_skill0" + i);
        }
        /**
         * 怪物右面攻击的技能
         */
        for (int i = 8; i < 16; i++) {
            images[i] = ImageUtil.getImage("boss_left_skill0" + (i - 8));
        }
    }

    public BossArrow(MapleStoryClient msc, int x, int y,Direction dir) {
        this();
        this.msc = msc;
        this.x = x;
        this.y = y;
        this.dir = dir;
    }

    public BossArrow() {
        this.speed = 25;
        this.live = true;
        this.width = images[0].getWidth(null);
        this.height = images[0].getHeight(null);
    }
    private int count;
    private int step;

    @Override
    public void draw(Graphics g) {
        if (!live){
            msc.bossArrows.remove(this);
            return;
        }
        switch (dir){
            case RIGHT:
                if (count++ % 5 == 0) {
                    g.drawImage(images[step++ % 8], x, y, null);
                } else {
                    g.drawImage(images[step % 8], x, y, null);
                }
                break;
            case LEFT:
                if (count++ % 5 == 0) {
                    g.drawImage(images[step++ % 8 + 8], x, y, null);
                } else {
                    g.drawImage(images[step % 8 + 8], x, y, null);
                }
                break;
            default:
                break;
        }
        this.move();
    }

    @Override
    public void move() {
        switch (dir) {
            case RIGHT:
                this.x += speed;
                break;
            case LEFT:
                this.x -= speed;
                break;
            default:
                break;
        }
        outOfBound();
    }
    private void outOfBound() {
        if (this.x < -800 || this.x > Constant.GAME_WINDOW_WIDTH) {
            this.live = false;
        }
    }
    public boolean hit(Hero hero){
        if (this.getRectangle().intersects(hero.getRectangle()) && this.live == true && hero.action !=Action.DIE){
                this.live = false;
                hero.HP-=100;
                if (hero.HP<=0){
                    hero.HP = 0;
                    hero.action = Action.DIE;
                }
            return true;
        }
        return false;
    }
}
